import { request } from '../../../../services/request';

// 获取点检任务详情（待点检状态使用）
export const getDeviceSpotDetailApi = async (planId: string) => {
    const requestBody = {
        plan_id: planId
    };

    // console.log('获取点检任务详情 - 请求数据:', requestBody);

    try {
        const response = await request('/app/appDeviceInfo/getDeviceSpotItem', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });

        // console.log('获取点检任务详情 - 接口返回:', response);
        return response;
    } catch (error) {
        console.error('获取点检任务详情失败:', error);
        throw error;
    }
};

// 获取点检记录（待复核和已复核状态使用）
export const getDeviceSpotRecordApi = async (deviceId: string, planId: string, cycleId: string) => {
    const requestBody = {
        device_id: deviceId,
        plan_id: planId,
        cycle_id: cycleId
    };

    console.log('获取点检记录 - 请求数据:', requestBody);

    try {
        const response = await request('/app/appDeviceInfo/getDeviceSpotRecord', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });

        console.log('获取点检记录 - 接口返回:', response);
        return response;
    } catch (error) {
        console.error('获取点检记录失败:', error);
        throw error;
    }
};

// 执行点检任务
export const execDeviceSpotApi = async (data: any) => {
    // console.log('执行点检任务 - 请求数据:', data);

    try {
        const response = await request('/app/appDeviceInfo/execDeviceSpotCheck', {
            method: 'POST',
            body: JSON.stringify(data)
        });

        // console.log('执行点检任务 - 接口返回:', response);
        return response;
    } catch (error) {
        console.error('执行点检任务失败:', error);
        throw error;
    }
};

// 复核点检计划
export const confirmSpotCheckPlanApi = async (planId: string, confirmRemark: string) => {
    const requestBody = {
        confirm_remark: confirmRemark,
        plan_id: planId
    };

    console.log('复核点检计划 - 请求数据:', requestBody);

    try {
        const response = await request('/app/appDeviceInfo/confirmSpotCheckPlan', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });

        console.log('复核点检计划 - 接口返回:', response);
        return response;
    } catch (error) {
        console.error('复核点检计划失败:', error);
        throw error;
    }
}; 